@gramio/keyboards
Framework-agnostic Telegram bot keyboard builder with many cool features!
Installation (if you don't use GramIO)
npm i @gramio/keyboards
Simple Keyboard
import { Keyboard } from "@gramio/keyboards";
const keyboard = new Keyboard()
.text("first row")
.row()
.text("second row")
.build();
Usage with Frameworks
Send via GramIO
import { Bot, Keyboard } from "gramio";
const bot = new Bot(process.env.TOKEN);
const data = ["Apple", "Realme", "Tesla", "Xiaomi"];
bot.on("message", (ctx) => {
return ctx.reply("test", {
reply_markup: new Keyboard()
.columns(1)
.text("simple keyboard")
.add(...data.map((x) => Keyboard.text(x)))
.filter(({ button }) => button.text !== "Tesla"),
});
});
import { Keyboard } from "@gramio/keyboards";
import { Bot } from "grammy";
const bot = new Bot(process.env.TOKEN);
const data = ["Apple", "Realme", "Tesla", "Xiaomi"];
bot.on("message", (ctx) => {
return ctx.reply("test", {
reply_markup: new Keyboard()
.columns(1)
.text("simple keyboard")
.add(...data.map((x) => Keyboard.text(x)))
.filter(({ button }) => button.text !== "Tesla")
.build(),
});
});
bot.start();
Result
{
"keyboard": [
[
{
"text": "simple keyboard"
}
],
[
{
"text": "Apple"
}
],
[
{
"text": "Realme"
}
],
[
{
"text": "Xiaomi"
}
]
],
"one_time_keyboard": false,
"is_persistent": false,
"selective": false,
"resize_keyboard": true
}